package com.edu.dao;

import com.edu.entity.User;
import com.edu.utils.JdbcHelper;

import java.sql.SQLException;
import java.util.List;

public class UserDao {
    // 用户登录
    public List<User> login(User user) throws SQLException {
        String sql = "select * from user where username = ?";
        List userlist = JdbcHelper.query(sql, User.class,user.getUsername());
        return userlist;
    }
    // 用户注册（必定是普通用户）
    public void register(User user) throws SQLException{
        String sql = "insert into user(username,password,ident) " +
                "values (?,?,?)";
        JdbcHelper.update(sql,user.getUsername(),user.getPassword(),0);
    }

    public User findone(User user) throws SQLException {
        String sql = "select * from user where username = ?";
        List<User> list = JdbcHelper.query(sql, User.class, user.getUsername());
        if(list.size() != 0){
            return list.get(0);
        }
        return null;
    }

}
